<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : shoplink.class.php   FILE_PATH : \\classes\application\shoplink.class.php
 * ....商铺友情连接类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Sep 07 14:52:00 CST 2007
 */

class ShopLinkClass extends FrameWork {
	/**
	 * 新增商铺友情连接
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function addLink($input_param){
		$valueArray = array();
		//print_r($input_param);exit;
		$valueArray['shop_id'] = $input_param['hideShopId'];
		if ($valueArray['link_id'] != ""){
			$valueArray['link_id'] = $input_param['hideLinkId'];
		}
		$valueArray['link_shop_id'] = $input_param['txtLinkShop'];
		$is_exist_link = $this->isExistLink($valueArray['shop_id'],$valueArray['link_shop_id']);
		if ($is_exist_link == false){
			$insert_rs = $GLOBALS['db']->InsertRow($valueArray, 'shop_link', 'link_id');
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 删除某个商铺的友情连接
	 *
	 * @param var[] $input_id
	 * @param int $shop_id
	 * @return boolen
	 */
	function deleteOperateLink($input_id,$shop_id){
		if (is_array($input_id)){
			foreach ($input_id as $value){
				$result = $this->_deleteLink($value,$shop_id);
				if ($result !== true){
					return false;
				}else {
					unset($result);
				}
			}
		}else{
			$result = $this->_deleteLink($input_id,$shop_id);
			if ($result !== true){
				return false;
			}
		}
		return true;
	}

	/**
	 * 删除某个商铺的友情连接
	 *
	 * @param int $link_id
	 * @param int $shop_id
	 * @return boolen
	 */
	function _deleteLink($link_id,$shop_id){
		if (intval($link_id) > 0){
			$del_rs = $GLOBALS['db']->DeleOneRow(intval($link_id),'shop_link','link_id','and shop_id = '.$shop_id);
		}
		return $del_rs;
	}

	/**
	 * 判断某商铺的某友情连接商铺是否存在
	 *
	 * @param int $shop_id  商铺ID
	 * @param int $link_shop_id  友情连接商铺ID
	 * @return boolen
	 */
	function isExistLink($shop_id,$link_shop_id){
		$exist_row = $GLOBALS['db']->GetList("and shop_id='" . $shop_id . "' and link_shop_id='" . $link_shop_id . "'",$page,'shop_link','link_id');
		
		if ($exist_row[0]['link_id'] == ''){
			return false;
		}
		return true;
	}

	/**
	 * 得到商铺友情连接
	 *
	 * @param int $shop_id
	 * @return var[]
	 */
	function getLink($condition,&$obj_page){
		$substr = $this->_conditionSearch($condition);
		$link_array = $GLOBALS['db']->GetJoinList($obj_page,array('shop_link','shop_info'),"inner join",array("shop_link.link_shop_id=shop_info.member_id"),array('*','shop_id as lshop_id,shop_name,shop_name as my_shop_name,member_id,shop_domain'),$substr,'',array(" link_id desc"));
		return $link_array;
	}
	
	/**
	 * 构造检索条件
	 * @author workflow Develop Team     
	 * @param  $condition 
	 * @return string
	 */
	function _conditionSearch($condition){
		$condition_str = '';
		
		//店铺ID
		if ($condition['shop_id'] != ''){
			$condition_str .= " and shop_link.shop_id = '".$condition['shop_id']."'";
		}
		//店铺名称模糊搜索
		if ($condition['like_shop_name'] != ''){
			$condition_str .= " and shop_info.shop_name like '%".$condition['like_shop_name']."%'";
		}
		return $condition_str;
	}
	
	/**
	 * 得到商铺友情连接 以商铺为列表，链接为数量
	 *
	 * @param int $shop_id
	 * @return var[]
	 */
	function getLinkByShop($condition,&$obj_page){
		$substr = $this->_conditionSearch($condition);
		$link_array = $GLOBALS['db']->GetJoinList($obj_page,array('shop_info','shop_link'),"left join",array("shop_info.shop_id=shop_link.shop_id"),array('shop_id as lshop_id,shop_name,shop_name as my_shop_name,member_id,shop_domain','link_id'),$substr,'',array(''),array(" shop_id"));
		return $link_array;
	}
}
?>